define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
/*            $("#c-goods_sku").data("params", function (obj) {
                return  {custom: {shop_id: $("#c-shop_id").val()}} ;
            });*/

            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/index' + location.search,
                    add_url: 'order/add',
                    edit_url: 'order/edit',
                    del_url: 'order/del',
                    multi_url: 'order/multi',
                    import_url: 'order/import',
                    table: 'order',
                }
            });


            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'order_create_time',
                searchFormVisible: true,
                searchFormTemplate: 'customformtpl',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'shop.name', title: __('Shops_id')},
                        {field: 'order_no', title: __('Order_no'), operate: 'LIKE'},
                        {field: 'goods.name', title: __('Goods_id')},
                        {field: 'goodssku.sku_name', title: __('Goodssku_id')},
                        {field: 'order_amount', title: __('Order_amount'), operate:'BETWEEN'},
                        {field: 'quantity', title: __('Quantity')},
                        {field: 'tk_discount_amount', title: __('Tk_discount_amount'), operate:'BETWEEN'},
                        {field: 'customer_transport_fee', title: __('Customer_transport_fee'), operate:'BETWEEN'},
                        {field: 'tk_transport_fee_discount', title: __('Tk_transport_fee_discount'), operate:'BETWEEN'},
                        {field: 'shop_discount_amount', title: __('Shop_discount_amount'), operate:'BETWEEN'},
                        {field: 'actual_order_amount', title: __('Actual_order_amount'), operate:'BETWEEN'},
                        {field: 'order_create_time', title: __('Order_create_time'), operate: 'LIKE', formatter: Table.api.formatter.datetime},
                        {field: 'order_status', title: __('Order_status'), operate: 'LIKE', formatter: Table.api.formatter.status},
                        {field: 'refund_amount', title: __('Refund_amount'), operate: 'LIKE'},
                        {field: 'shipping_time', title: __('Shipping_time'), operate: 'LIKE', formatter: Table.api.formatter.datetime},
                        {field: 'delivered_time', title: __('Delivered_time'), operate: 'LIKE', formatter: Table.api.formatter.datetime},
                        {field: 'shipping_type', title: __('Shipping_type'), searchList: {"0":__('Shipping_type 0'),"1":__('Shipping_type 1')}, formatter: Table.api.formatter.normal},
                        {field: 'goods_cost', title: __('Goods_cost'), operate:'BETWEEN'},
                        {field: 'extra_fee', title: __('Extra_fee'), operate:'BETWEEN'},
                        {field: 'tk_handle_fee', title: __('Tk_handle_fee'), operate:'BETWEEN'},
                        {field: 'tk_commission_fee', title: __('Tk_commission_fee'), operate:'BETWEEN'},
                        {field: 'added_value_fee', title: __('Added_value_fee'), operate:'BETWEEN'},
                        {field: 'tariff_fee', title: __('Tariff_fee'), operate:'BETWEEN'},
                        {field: 'sfp_fee', title: __('Sfp_fee'), operate:'BETWEEN'},
                        {field: 'bonus_cash_fee', title: __('Bonus_cash_fee'), operate:'BETWEEN'},
                        {field: 'super_coupon_fee', title: __('Super_coupon_fee'), operate:'BETWEEN'},
                        {field: 'affiliate_fee', title: __('Affiliate_fee'), operate:'BETWEEN'},
                        {field: 'china_shipping_fee', title: __('China_shipping_fee'), operate:'BETWEEN'},
                        {field: 'oversea_shipping_fee', title: __('Oversea_shipping_fee'), operate:'BETWEEN'},
                        {field: 'oversea_pack_fee', title: __('Oversea_pack_fee'), operate:'BETWEEN'},
                        {field: 'oversea_extra_fee', title: __('Oversea_extra_fee'), operate:'BETWEEN'},
                        {field: 'estimated_profit', title: __('Estimated_profit'), operate:'BETWEEN'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
